import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import junit.framework.TestCase;

/**
 * @author Tsarev Oleg<br/>
 *		   <b>mail:</b> tsarev.oi@mail.ru<br/>
 *         <b>date:</b> 14.07.2010<br/>
 *         <b>time:</b> 17:11:24
 *
 */
public class ImporterTest extends TestCase {
	
	private static final String SOURCE_FILE = "tests/java/source_file.txt";
	private static final String TARGET_FILE = "tests/java/target_file.txt";
	private static final String TARGET_ORIGINAL_FILE = "tests/java/target_file_original.txt";

	/**
	 * Test method for {@link Importer#main(java.lang.String[])}.
	 * @throws IOException 
	 */
	public void testMain() throws IOException {
		File source = new File(SOURCE_FILE);
		File targetOriginal = new File(TARGET_ORIGINAL_FILE);
		
		if (source.exists() && targetOriginal.exists()) {
			String[] args = {SOURCE_FILE,TARGET_FILE};
			Importer.main(args);
			
			File target = new File(TARGET_FILE);
			if (target.exists()) {
				
				assertEquals("Different files (size)",target.length(),targetOriginal.length());
				
				BufferedReader targetReader = new BufferedReader(new FileReader(target));
				BufferedReader originalReader = new BufferedReader(new FileReader(targetOriginal));

				int lineCounter = 1;
				String targetString = targetReader.readLine();
				String originalString = originalReader.readLine();
				while (targetString != null || originalString != null) {
					
					assertNotNull("Different files (Line: "+lineCounter+")",targetString);
					assertNotNull("Different files (Line: "+lineCounter+")",originalString);
					assertEquals("Different files (Line: "+lineCounter+")", targetString, originalString);
					
					lineCounter++;
					targetString = targetReader.readLine();
					originalString = originalReader.readLine();
				}
			} else {
				fail("Target file not exists!!!");
			}
		} else {
			fail("Source files not exists!!!");
		}
	}

}
